{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Downloaded: ablobcatheart.png\n",
      "Downloaded: ablobcatheartbroken.png\n",
      "Downloaded: blobcatheartpride.png\n",
      "Downloaded: blobcatlove.png\n",
      "Downloaded: blobcatkissheart.png\n",
      "Downloaded: blobcatsnuggle.png\n",
      "Downloaded: blobcatcomfy.png\n",
      "Downloaded: blobcatcomftears.png\n",
      "Downloaded: blobcatfacepalm.png\n",
      "Downloaded: blobcat0_0.png\n",
      "Downloaded: blobcatangry.png\n",
      "Downloaded: blobcatblush.png\n",
      "Downloaded: blobcatcoffee.png\n",
      "Downloaded: blobcatcry.png\n",
      "Downloaded: blobcatdead.png\n",
      "Downloaded: blobcatdisturbed.png\n",
      "Downloaded: blobcatfearful.png\n",
      "Downloaded: blobcatfingerguns.png\n",
      "Downloaded: blobcatflip.png\n",
      "Downloaded: blobcatflower.png\n",
      "Downloaded: blobcatgay.png\n",
      "Downloaded: blobcatneutral.png\n",
      "Downloaded: blobcatopenmouth.png\n",
      "Downloaded: blobcatsadreach.png\n",
      "Downloaded: blobcatscared.png\n",
      "Downloaded: blobcatnomblobcat.png\n",
      "Downloaded: blobcatpresentred.png\n",
      "Downloaded: blobcatread.png\n",
      "Downloaded: blobcatsipsweat.png\n",
      "Downloaded: blobcatsnapped.png\n",
      "Downloaded: blobcatthink.png\n",
      "Downloaded: blobcattriumph.png\n",
      "Downloaded: blobcatumm.png\n",
      "Downloaded: blobcatverified.png\n",
      "Downloaded: blobcatbox.png\n",
      "Downloaded: blobcatcaged.png\n",
      "Downloaded: blobcatgooglytrash.png\n",
      "Downloaded: blobcatheadphones.png\n",
      "Downloaded: blobcathighfive.png\n",
      "Downloaded: blobcatmelt.png\n",
      "Downloaded: blobcatmeltthumb.png\n",
      "Downloaded: blobcatnotlikethis.png\n",
      "Downloaded: blobcatsaitama.png\n",
      "Downloaded: blobcatyandere.png\n",
      "Downloaded: blobcatpeek2.png\n",
      "Downloaded: blobcatpeekaboo.png\n",
      "Downloaded: blobcatphoto.png\n",
      "Downloaded: ablobcatattentionreverse.png\n",
      "Downloaded: ablobcatreachrev.png\n",
      "Downloaded: ablobcatwave.png\n",
      "Downloaded: blobcatalt.png\n",
      "Downloaded: blobcatpolice.png\n",
      "Downloaded: blobcatshocked.png\n",
      "Downloaded: ablobcatrainbow.png\n",
      "All files downloaded.\n"
     ]
    }
   ],
   "source": [
    "import requests\n",
    "import os\n",
    "\n",
    "# 文件链接列表\n",
    "# 文件链接列表\n",
    "urls = [\n",
    "    \"https://npm.elemecdn.com/blobcat@1.0.0/ablobcatheart.png\",\n",
    "    \"https://npm.elemecdn.com/blobcat@1.0.0/ablobcatheartbroken.png\",\n",
    "    \"https://npm.elemecdn.com/blobcat@1.0.0/blobcatheartpride.png\",\n",
    "    \"https://npm.elemecdn.com/blobcat@1.0.0/blobcatlove.png\",\n",
    "    \"https://npm.elemecdn.com/blobcat@1.0.0/blobcatkissheart.png\",\n",
    "    \"https://npm.elemecdn.com/blobcat@1.0.0/blobcatsnuggle.png\",\n",
    "    \"https://npm.elemecdn.com/blobcat@1.0.0/blobcatcomfy.png\",\n",
    "    \"https://npm.elemecdn.com/blobcat@1.0.0/blobcatcomftears.png\",\n",
    "    \"https://npm.elemecdn.com/blobcat@1.0.0/blobcatfacepalm.png\",\n",
    "    \"https://npm.elemecdn.com/blobcat@1.0.0/blobcat0_0.png\",\n",
    "    \"https://npm.elemecdn.com/blobcat@1.0.0/blobcatangry.png\",\n",
    "    \"https://npm.elemecdn.com/blobcat@1.0.0/blobcatblush.png\",\n",
    "    \"https://npm.elemecdn.com/blobcat@1.0.0/blobcatcoffee.png\",\n",
    "    \"https://npm.elemecdn.com/blobcat@1.0.0/blobcatcry.png\",\n",
    "    \"https://npm.elemecdn.com/blobcat@1.0.0/blobcatdeath.png\",\n",
    "    \"https://npm.elemecdn.com/blobcat@1.0.0/blobcatdisturbed.png\",\n",
    "    \"https://npm.elemecdn.com/blobcat@1.0.0/blobcatfearful.png\",\n",
    "    \"https://npm.elemecdn.com/blobcat@1.0.0/blobcatfingerguns.png\",\n",
    "    \"https://npm.elemecdn.com/blobcat@1.0.0/blobcatflip.png\",\n",
    "    \"https://npm.elemecdn.com/blobcat@1.0.0/blobcatflower.png\",\n",
    "    \"https://npm.elemecdn.com/blobcat@1.0.0/blobcatgay.png\",\n",
    "    \"https://npm.elemecdn.com/blobcat@1.0.0/blobcatneutral.png\",\n",
    "    \"https://npm.elemecdn.com/blobcat@1.0.0/blobcatopenmouth.png\",\n",
    "    \"https://npm.elemecdn.com/blobcat@1.0.0/blobcatsadreach.png\",\n",
    "    \"https://npm.elemecdn.com/blobcat@1.0.0/blobcatscared.png\",\n",
    "    \"https://npm.elemecdn.com/blobcat@1.0.0/blobcatnomblobcat.png\",\n",
    "    \"https://npm.elemecdn.com/blobcat@1.0.0/blobcatpresentred.png\",\n",
    "    \"https://npm.elemecdn.com/blobcat@1.0.0/blobcatread.png\",\n",
    "    \"https://npm.elemecdn.com/blobcat@1.0.0/blobcatsipsweat.png\",\n",
    "    \"https://npm.elemecdn.com/blobcat@1.0.0/blobcatsnapped.png\",\n",
    "    \"https://npm.elemecdn.com/blobcat@1.0.0/blobcatthink.png\",\n",
    "    \"https://npm.elemecdn.com/blobcat@1.0.0/blobcattriumph.png\",\n",
    "    \"https://npm.elemecdn.com/blobcat@1.0.0/blobcatumm.png\",\n",
    "    \"https://npm.elemecdn.com/blobcat@1.0.0/blobcatverified.png\",\n",
    "    \"https://npm.elemecdn.com/blobcat@1.0.0/blobcatbox.png\",\n",
    "    \"https://npm.elemecdn.com/blobcat@1.0.0/blobcatcaged.png\",\n",
    "    \"https://npm.elemecdn.com/blobcat@1.0.0/blobcatgooglytrash.png\",\n",
    "    \"https://npm.elemecdn.com/blobcat@1.0.0/blobcatheadphones.png\",\n",
    "    \"https://npm.elemecdn.com/blobcat@1.0.0/blobcathighfive.png\",\n",
    "    \"https://npm.elemecdn.com/blobcat@1.0.0/blobcatmelt.png\",\n",
    "    \"https://npm.elemecdn.com/blobcat@1.0.0/blobcatmeltthumb.png\",\n",
    "    \"https://npm.elemecdn.com/blobcat@1.0.0/blobcatnotlikethis.png\",\n",
    "    \"https://npm.elemecdn.com/blobcat@1.0.0/blobcatsaitama.png\",\n",
    "    \"https://npm.elemecdn.com/blobcat@1.0.0/blobcatyandere.png\",\n",
    "    \"https://npm.elemecdn.com/blobcat@1.0.0/blobcatpeek2.png\",\n",
    "    \"https://npm.elemecdn.com/blobcat@1.0.0/blobcatpeekaboo.png\",\n",
    "    \"https://npm.elemecdn.com/blobcat@1.0.0/blobcatphoto.png\",\n",
    "    \"https://npm.elemecdn.com/blobcat@1.0.0/ablobcatattentionreverse.png\",\n",
    "    \"https://npm.elemecdn.com/blobcat@1.0.0/ablobcatreachrev.png\",\n",
    "    \"https://npm.elemecdn.com/blobcat@1.0.0/ablobcatwave.png\",\n",
    "    \"https://npm.elemecdn.com/blobcat@1.0.0/blobcatalt.png\",\n",
    "    \"https://npm.elemecdn.com/blobcat@1.0.0/blobcatpolice.png\",\n",
    "    \"https://npm.elemecdn.com/blobcat@1.0.0/blobcatshocked.png\",\n",
    "    \"https://npm.elemecdn.com/blobcat@1.0.0/ablobcatrainbow.png\"\n",
    "]\n",
    "\n",
    "# 保存文件的目标文件夹\n",
    "target_folder = \"blobcat\"\n",
    "os.makedirs(target_folder, exist_ok=True)\n",
    "\n",
    "# 设置新的前缀\n",
    "new_prefix = \"\"\n",
    "\n",
    "# 下载文件\n",
    "for url in urls:\n",
    "    # 获取原始文件名\n",
    "    original_file_name = os.path.basename(url)\n",
    "    \n",
    "    # # 查找原始前缀的结尾位置\n",
    "    # underscore_index = original_file_name\n",
    "    \n",
    "    # # 如果找到下划线，替换前缀\n",
    "    # if underscore_index != -1:\n",
    "    #     # 获取原始前缀的部分之后的文件名\n",
    "    #     original_suffix = original_file_name[underscore_index:]\n",
    "    #     # 构造新的文件名\n",
    "    #     new_file_name = new_prefix + original_suffix[1:]\n",
    "    # else:\n",
    "    #     # 如果没有找到下划线，则直接添加新的前缀\n",
    "    #     new_file_name = new_prefix + original_file_name\n",
    "    \n",
    "    # 生成文件保存路径\n",
    "    file_path = original_file_name\n",
    "    \n",
    "    # 请求下载文件\n",
    "    response = requests.get(url)\n",
    "    \n",
    "    # 检查响应状态\n",
    "    if response.status_code == 200:\n",
    "        # 保存文件\n",
    "        with open(file_path, 'wb') as file:\n",
    "            file.write(response.content)\n",
    "        print(f\"Downloaded: {file_path}\")\n",
    "    else:\n",
    "        print(f\"Failed to download: {url}\")\n",
    "\n",
    "print(\"All files downloaded.\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Renamed: catbug\\不准色色.webp -> catbug\\catbug-不准色色.webp\n",
      "Renamed: catbug\\不要.webp -> catbug\\catbug-不要.webp\n",
      "Renamed: catbug\\不要呀.webp -> catbug\\catbug-不要呀.webp\n",
      "Renamed: catbug\\亲亲.webp -> catbug\\catbug-亲亲.webp\n",
      "Renamed: catbug\\亲脸.webp -> catbug\\catbug-亲脸.webp\n",
      "Renamed: catbug\\偷偷看.webp -> catbug\\catbug-偷偷看.webp\n",
      "Renamed: catbug\\偷偷给心.webp -> catbug\\catbug-偷偷给心.webp\n",
      "Renamed: catbug\\再见.webp -> catbug\\catbug-再见.webp\n",
      "Renamed: catbug\\吃掉你.webp -> catbug\\catbug-吃掉你.webp\n",
      "Renamed: catbug\\吹风.webp -> catbug\\catbug-吹风.webp\n",
      "Renamed: catbug\\呕吼.webp -> catbug\\catbug-呕吼.webp\n",
      "Renamed: catbug\\和我色色.webp -> catbug\\catbug-和我色色.webp\n",
      "Renamed: catbug\\咬你.webp -> catbug\\catbug-咬你.webp\n",
      "Renamed: catbug\\开心.webp -> catbug\\catbug-开心.webp\n",
      "Renamed: catbug\\思考中.webp -> catbug\\catbug-思考中.webp\n",
      "Renamed: catbug\\扭一扭.webp -> catbug\\catbug-扭一扭.webp\n",
      "Renamed: catbug\\扭屁股.webp -> catbug\\catbug-扭屁股.webp\n",
      "Renamed: catbug\\摇摇晃晃.webp -> catbug\\catbug-摇摇晃晃.webp\n",
      "Renamed: catbug\\无奈.webp -> catbug\\catbug-无奈.webp\n",
      "Renamed: catbug\\棒.webp -> catbug\\catbug-棒.webp\n",
      "Renamed: catbug\\点赞.webp -> catbug\\catbug-点赞.webp\n",
      "Renamed: catbug\\爱你.webp -> catbug\\catbug-爱你.webp\n",
      "Renamed: catbug\\爱你2.webp -> catbug\\catbug-爱你2.webp\n",
      "Renamed: catbug\\牛.webp -> catbug\\catbug-牛.webp\n",
      "Renamed: catbug\\生气.webp -> catbug\\catbug-生气.webp\n",
      "Renamed: catbug\\睡觉.webp -> catbug\\catbug-睡觉.webp\n",
      "Renamed: catbug\\耍帅.webp -> catbug\\catbug-耍帅.webp\n",
      "Renamed: catbug\\脸红.webp -> catbug\\catbug-脸红.webp\n",
      "Renamed: catbug\\膜拜.webp -> catbug\\catbug-膜拜.webp\n",
      "Renamed: catbug\\舔屏.webp -> catbug\\catbug-舔屏.webp\n",
      "Renamed: catbug\\贴贴.webp -> catbug\\catbug-贴贴.webp\n",
      "Renamed: catbug\\问号.webp -> catbug\\catbug-问号.webp\n",
      "All files renamed.\n"
     ]
    }
   ],
   "source": [
    "# 给文件夹下/catbug/下的所有webp文件添加前缀”catbug-“\n",
    "import os\n",
    "import shutil\n",
    "\n",
    "target_folder = \"catbug\"\n",
    "new_prefix = \"catbug-\"\n",
    "\n",
    "# 遍历文件夹\n",
    "for root, dirs, files in os.walk(target_folder):\n",
    "    for file in files:\n",
    "        # 检查文件扩展名\n",
    "        if file.endswith(\".webp\"):\n",
    "            # 生成文件路径\n",
    "            file_path = os.path.join(root, file)\n",
    "            # 生成新的文件路径\n",
    "            new_file_path = os.path.join(root, new_prefix + file)\n",
    "            # 重命名文件\n",
    "            os.rename(file_path, new_file_path)\n",
    "            print(f\"Renamed: {file_path} -> {new_file_path}\")\n",
    "            \n",
    "print(\"All files renamed.\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "正在下载图片: https://expression.qjqq.cn/1/663c6390ccf24.webp\n",
      "图片已下载: death\\death-搬砖.png\n",
      "正在下载图片: https://expression.qjqq.cn/1/663c6390cce3d.webp\n",
      "图片已下载: death\\death-报告.png\n",
      "正在下载图片: https://expression.qjqq.cn/1/663c6390cc7fb.webp\n",
      "图片已下载: death\\death-悲伤眼泪.png\n",
      "正在下载图片: https://expression.qjqq.cn/1/663c6391e8702.webp\n",
      "图片已下载: death\\death-呆萌.png\n",
      "正在下载图片: https://expression.qjqq.cn/1/663c6391e879b.webp\n",
      "图片已下载: death\\death-发抖.png\n",
      "正在下载图片: https://expression.qjqq.cn/1/663c6391e8e91.webp\n",
      "图片已下载: death\\death-奔跑.png\n",
      "正在下载图片: https://expression.qjqq.cn/1/663c6420bb399.webp\n",
      "图片已下载: death\\death-孤独.png\n",
      "正在下载图片: https://expression.qjqq.cn/1/663c6420bbb49.webp\n",
      "图片已下载: death\\death-孤独寂寞.png\n",
      "正在下载图片: https://expression.qjqq.cn/1/663c6420bbb64.webp\n",
      "图片已下载: death\\death-害怕.png\n",
      "正在下载图片: https://expression.qjqq.cn/1/663c6421b64c0.webp\n",
      "图片已下载: death\\death-坏笑.png\n",
      "正在下载图片: https://expression.qjqq.cn/1/663c6421a8114.webp\n",
      "图片已下载: death\\death-黑脸.png\n",
      "正在下载图片: https://expression.qjqq.cn/1/663c6421a9c7d.webp\n",
      "图片已下载: death\\death-黑线.png\n",
      "正在下载图片: https://expression.qjqq.cn/1/663c642293552.webp\n",
      "图片已下载: death\\death-可怜无助.png\n",
      "正在下载图片: https://expression.qjqq.cn/1/663c6422a1c39.webp\n",
      "图片已下载: death\\death-空洞呆.png\n",
      "正在下载图片: https://expression.qjqq.cn/1/663c6422a9f11.webp\n",
      "图片已下载: death\\death-难过.png\n",
      "正在下载图片: https://expression.qjqq.cn/1/663c6423865fb.webp\n",
      "图片已下载: death\\death-谁也不爱.png\n",
      "正在下载图片: https://expression.qjqq.cn/1/663c642374a88.webp\n",
      "图片已下载: death\\death-弱小无助.png\n",
      "正在下载图片: https://expression.qjqq.cn/1/663c6423a4209.webp\n",
      "图片已下载: death\\death-生气.png\n",
      "正在下载图片: https://expression.qjqq.cn/1/663c642457735.webp\n",
      "图片已下载: death\\death-死神驾到.png\n",
      "正在下载图片: https://expression.qjqq.cn/1/663c6424817ab.webp\n",
      "图片已下载: death\\death-死神施法.png\n",
      "正在下载图片: https://expression.qjqq.cn/1/663c642483aca.webp\n",
      "图片已下载: death\\death-死神巫师.png\n",
      "正在下载图片: https://expression.qjqq.cn/1/663c64255054a.webp\n",
      "图片已下载: death\\death-逃跑.png\n",
      "正在下载图片: https://expression.qjqq.cn/1/663c642566bb9.webp\n",
      "图片已下载: death\\death-痛苦无助.png\n",
      "正在下载图片: https://expression.qjqq.cn/1/663c6425a0801.webp\n",
      "图片已下载: death\\death-吓人.png\n",
      "正在下载图片: https://expression.qjqq.cn/1/663c642623ba2.webp\n",
      "图片已下载: death\\death-嫌弃讨厌.png\n",
      "正在下载图片: https://expression.qjqq.cn/1/663c642659691.webp\n",
      "图片已下载: death\\death-邪恶的笑.png\n",
      "正在下载图片: https://expression.qjqq.cn/1/663c642693027.webp\n",
      "图片已下载: death\\death-心痛.png\n",
      "正在下载图片: https://expression.qjqq.cn/1/663c64272fd9e.webp\n",
      "图片已下载: death\\death-摘下面具.png\n",
      "所有图片下载完成。\n"
     ]
    }
   ],
   "source": [
    "import json\n",
    "import requests\n",
    "from bs4 import BeautifulSoup\n",
    "import os\n",
    "\n",
    "# 假设json_data是包含上述JSON数据的字符串\n",
    "json_data = '''\n",
    "{\n",
    "  \"胆小鬼\": {\n",
    "    \"type\": \"image\",\n",
    "    \"container\": [\n",
    "      {\n",
    "        \"icon\": \"https://expression.qjqq.cn/1/663c6390ccf24.webp\",\n",
    "        \"text\": \"death-搬砖\"\n",
    "      },\n",
    "      {\n",
    "        \"icon\": \"https://expression.qjqq.cn/1/663c6390cce3d.webp\",\n",
    "        \"text\": \"death-报告\"\n",
    "      },\n",
    "      {\n",
    "        \"icon\": \"https://expression.qjqq.cn/1/663c6390cc7fb.webp\",\n",
    "        \"text\": \"death-悲伤眼泪\"\n",
    "      },\n",
    "      {\n",
    "        \"icon\": \"https://expression.qjqq.cn/1/663c6391e8702.webp\",\n",
    "        \"text\": \"death-呆萌\"\n",
    "      },\n",
    "      {\n",
    "        \"icon\": \"https://expression.qjqq.cn/1/663c6391e879b.webp\",\n",
    "        \"text\": \"death-发抖\"\n",
    "      },\n",
    "      {\n",
    "        \"icon\": \"https://expression.qjqq.cn/1/663c6391e8e91.webp\",\n",
    "        \"text\": \"death-奔跑\"\n",
    "      },\n",
    "      {\n",
    "        \"icon\": \"https://expression.qjqq.cn/1/663c6420bb399.webp\",\n",
    "        \"text\": \"death-孤独\"\n",
    "      },\n",
    "      {\n",
    "        \"icon\": \"https://expression.qjqq.cn/1/663c6420bbb49.webp\",\n",
    "        \"text\": \"death-孤独寂寞\"\n",
    "      },\n",
    "      {\n",
    "        \"icon\": \"https://expression.qjqq.cn/1/663c6420bbb64.webp\",\n",
    "        \"text\": \"death-害怕\"\n",
    "      },\n",
    "      {\n",
    "        \"icon\": \"https://expression.qjqq.cn/1/663c6421b64c0.webp\",\n",
    "        \"text\": \"death-坏笑\"\n",
    "      },\n",
    "      {\n",
    "        \"icon\": \"https://expression.qjqq.cn/1/663c6421a8114.webp\",\n",
    "        \"text\": \"death-黑脸\"\n",
    "      },\n",
    "      {\n",
    "        \"icon\": \"https://expression.qjqq.cn/1/663c6421a9c7d.webp\",\n",
    "        \"text\": \"death-黑线\"\n",
    "      },\n",
    "      {\n",
    "        \"icon\": \"https://expression.qjqq.cn/1/663c642293552.webp\",\n",
    "        \"text\": \"death-可怜无助\"\n",
    "      },\n",
    "      {\n",
    "        \"icon\": \"https://expression.qjqq.cn/1/663c6422a1c39.webp\",\n",
    "        \"text\": \"death-空洞呆\"\n",
    "      },\n",
    "      {\n",
    "        \"icon\": \"https://expression.qjqq.cn/1/663c6422a9f11.webp\",\n",
    "        \"text\": \"death-难过\"\n",
    "      },\n",
    "      {\n",
    "        \"icon\": \"https://expression.qjqq.cn/1/663c6423865fb.webp\",\n",
    "        \"text\": \"death-谁也不爱\"\n",
    "      },\n",
    "      {\n",
    "        \"icon\": \"https://expression.qjqq.cn/1/663c642374a88.webp\",\n",
    "        \"text\": \"death-弱小无助\"\n",
    "      },\n",
    "      {\n",
    "        \"icon\": \"https://expression.qjqq.cn/1/663c6423a4209.webp\",\n",
    "        \"text\": \"death-生气\"\n",
    "      },\n",
    "      {\n",
    "        \"icon\": \"https://expression.qjqq.cn/1/663c642457735.webp\",\n",
    "        \"text\": \"death-死神驾到\"\n",
    "      },\n",
    "      {\n",
    "        \"icon\": \"https://expression.qjqq.cn/1/663c6424817ab.webp\",\n",
    "        \"text\": \"death-死神施法\"\n",
    "      },\n",
    "      {\n",
    "        \"icon\": \"https://expression.qjqq.cn/1/663c642483aca.webp\",\n",
    "        \"text\": \"death-死神巫师\"\n",
    "      },\n",
    "      {\n",
    "        \"icon\": \"https://expression.qjqq.cn/1/663c64255054a.webp\",\n",
    "        \"text\": \"death-逃跑\"\n",
    "      },\n",
    "      {\n",
    "        \"icon\": \"https://expression.qjqq.cn/1/663c642566bb9.webp\",\n",
    "        \"text\": \"death-痛苦无助\"\n",
    "      },\n",
    "      {\n",
    "        \"icon\": \"https://expression.qjqq.cn/1/663c6425a0801.webp\",\n",
    "        \"text\": \"death-吓人\"\n",
    "      },\n",
    "      {\n",
    "        \"icon\": \"https://expression.qjqq.cn/1/663c642623ba2.webp\",\n",
    "        \"text\": \"death-嫌弃讨厌\"\n",
    "      },\n",
    "      {\n",
    "        \"icon\": \"https://expression.qjqq.cn/1/663c642659691.webp\",\n",
    "        \"text\": \"death-邪恶的笑\"\n",
    "      },\n",
    "      {\n",
    "        \"icon\": \"https://expression.qjqq.cn/1/663c642693027.webp\",\n",
    "        \"text\": \"death-心痛\"\n",
    "      },\n",
    "      {\n",
    "        \"icon\": \"https://expression.qjqq.cn/1/663c64272fd9e.webp\",\n",
    "        \"text\": \"death-摘下面具\"\n",
    "      }\n",
    "    ]\n",
    "  }\n",
    "}\n",
    "'''\n",
    "\n",
    "# 将JSON字符串解析为Python字典\n",
    "data = json.loads(json_data)\n",
    "\n",
    "# 指定下载图片的文件夹\n",
    "download_folder = 'death'\n",
    "if not os.path.exists(download_folder):\n",
    "    os.makedirs(download_folder)\n",
    "\n",
    "# 遍历JSON数据中的图片链接\n",
    "for item in data[\"胆小鬼\"][\"container\"]:\n",
    "    text = item[\"text\"]  # 获取text字段\n",
    "    icon = item[\"icon\"]  # 获取icon字段\n",
    "    img_url = icon\n",
    "    \n",
    "    # 构造新的文件名\n",
    "    filename = f'{text}.png'\n",
    "    \n",
    "    print(f'正在下载图片: {img_url}')\n",
    "    \n",
    "    # 确保文件名不包含非法字符\n",
    "    filename = filename.replace('/', '-').replace('\\\\', '-')\n",
    "    \n",
    "    # 拼接完整的文件路径\n",
    "    file_path = os.path.join(download_folder, filename)\n",
    "    \n",
    "    # 发送HTTP请求下载图片\n",
    "    response = requests.get(img_url)\n",
    "    if response.status_code == 200:\n",
    "        # 打开文件并写入内容\n",
    "        with open(file_path, 'wb') as file:\n",
    "            file.write(response.content)\n",
    "        print(f'图片已下载: {file_path}')\n",
    "    else:\n",
    "        print(f'图片下载失败: {img_url}')\n",
    "\n",
    "print('所有图片下载完成。')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "base",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
